import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.border.*;
import java.util.*;

class MyListContainer extends MyComponentContainer {
    
    MyListContainer(String name, MyFrame frame) {
        super(new JList(), frame);
        ((JList)myComponent).setEnabled(false);
        ((JList)myComponent).addMouseListener(new MouseHandler());
        ((JList)myComponent).addMouseMotionListener(new MouseDragHandler());
        ((JList)myComponent).setBorder(new LineBorder(Color.LIGHT_GRAY));
    }
    //#########################################################################
    //#########################################################################
    public class MouseHandler extends MouseAdapter {
        public void mouseClicked(MouseEvent m) {
            if (m.getButton() == 3) {
                setChosen(true);
                showBorder();
                handleRightClickSelection();
                MyRightClickMenu popUpMenu = new MyRightClickMenu(MyListContainer.this,m.getX(),m.getY(),frame);
            }
            if (m.getButton()==MouseEvent.BUTTON1) {
                if (m.getClickCount()==2) {
                    JComponent eventObject =(JComponent) m.getComponent(); /* Get the component that is
                     responsable for the action */
                    MyPropertiesWindow properties = new MyPropertiesWindow(MyListContainer.this,frame);
                    /*Createing the properties window and send the object that is
                     resposable for the event*/
                } else if (m.getClickCount()==1 & m.isShiftDown()==false){
                    if (isChosen()==false) {
                        frame.panel.setCursor(new Cursor(Cursor.HAND_CURSOR));
                        showBorder();
                        setChosen(true);
                    }
                }
            }
        }
        
        public void mousePressed(MouseEvent m) {
            frame.panel.requestFocusInWindow();
            
            if (m.getButton()==MouseEvent.BUTTON1) {
                handleSelection(m);
                frame.panel.setCursor(new Cursor(Cursor.HAND_CURSOR));
                clickToAnchorX=m.getX();
                clickToAnchorY=m.getY();
            }
        }
        
        public void mouseEntered(MouseEvent m) {
            if (((JList)myComponent).isEnabled()==false && isChosen()==true) {
                frame.panel.setCursor(new Cursor(Cursor.HAND_CURSOR));
            }
        }
        
        public void mouseExited(MouseEvent m) {
            frame.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        
        public void mouseReleased(MouseEvent m) {
        handleUndo();
        }
    }
    //#########################################################################
    class MouseDragHandler extends MouseMotionAdapter {
        public void mouseDragged(MouseEvent evt) {
            handleDrag(evt);
        }
    }
}
